<template>
  <view></view>
</template>
<script>
export default {
  name: "BizPageGen",
  inheritAttrs: false,
};
</script>
<script setup>
import {
  ref,
  reactive,
  shallowRef,
  shallowReactive,
  computed,
  getCurrentInstance,
  toRefs,
  watch,
  provide,
  onMounted,
} from "vue";
//import useSkeletonDynmicTableSize from "./useSkeletonDynmicTableSize";
import { globalConfig } from "@gd-accbuild-core/config";

// scene-container-gen:start
import useGetCurUiTemplateInfo from "@gd-accbuild-core/hooks/useGetCurUiTemplateInfo";
import useCanvasRender from "@gd-accbuild-ui/biz-ui/hooks/useCanvasRender/useCanvasRender";
import buildInBizTemplateProps from "@gd-accbuild-core/hooks/buildInBizTemplateProps";
import useMergeMeta from "@gd-accbuild-core/hooks/useMergeMeta";
import { useStore } from "@gd-accbuild-core/store/hackVueStore";
const _store = useStore();
const { proxy: vm } = getCurrentInstance();

const props = defineProps({
  vmName: {
    type: String,
    default: "BizSearchformTablelistSimple",
  },
  ...buildInBizTemplateProps,
});
const {
  crudServiceVmTemplateConfig,
  isUseStaticResource,
  setterCrudServiceVmTemplateConfig,
  allBtnsEmitFormItemMetaConfig,
  filter_allBtnsEmitFormItemMetaConfig,
  ////
  operationBtnsConfig,
  toolBarConfig,
  setterAllTableBtnsConfig,
  filter_toolBarConfig,
  filter_operationBtnsConfig,
  filter_setterAllTableBtnsConfig,
  ////
  filter_tableCommonAttr,
  filter_tableBodyData,
  filter_dialogFormItemDynmicConfigList,
  filter_setterRemoteTableConfig,
  filter_getFirstItemAppendReqParamsIntoSearchForm,
  ////
  tableCommonAttr,
  tableColMetaList,
  tableColumnDynmicConfigList,
  tableBodyData,
  dialogFormItemDynmicConfigList,
  setterRemoteTableConfig,
  ////
  searchFormItemMetaList,
  searchFormItemDynmicConfigList,
  searchFormCommonAttr,
  searchFormData,
  setterRemoteSearchFormConfig,
  /////
  ////////
  fillFieldsIntoAddForm,
  appendFieldsIntoSearchForm,
  tablePageReq,
} = useMergeMeta({ props });
/////////////////////

const {
  isDesigner,
  templateContainerAttr,
  setterTemplateContainerAttr,
  getClassObjInBizTemplateCrudContainerWhenRender,
  canvasRenderPickedComp,
  ////////////
} = useCanvasRender({
  props,
  curTemplateAllCrudContainerKeys: ["table", "filter"],
  crudServiceVmTemplateConfig,
});
/**
 * 所有按钮引发的表单元数据配置:metaList
 */

/////树相关

const hasLeftTree = ref(false);
const treeLoading = ref(true);
const tableLoading = ref(true);
///////////////////
//
const _emits = defineEmits(["biz-pagegen-data-ok"]);

//组件增删改查接口的附加参数,用于设计器渲染请求 是否转发到优速搭服务器
const initMetaAndData = ({
  allOverrideParams = [{ templateInnerSearchPath: "", appendReqParams: {} }],
}) => {
  treeLoading.value = true;
  tableLoading.value = true;
  const appendReqParams =
    Array.isArray(allOverrideParams) && allOverrideParams.length === 1
      ? allOverrideParams[0]?.appendReqParams ?? {}
      : {};
  console.log(props.staticResource, "参考");
  ////
  const templateName =
    props.staticResource["uiOptions"].pageUiTemplateConfigs[props.templateIdx]
      .templateName;
  ////
  useGetCurUiTemplateInfo({
    templateName: templateName,
    templateIdx: props.templateIdx,
    templateInnerSearchPath: "templateProps.filter_tableCommonAttr",
    isUseStaticResource: isUseStaticResource.value,
    staticResource: props.staticResource,
    appendReqParams,
    allOverrideParams,
    store: _store,
  })
    .then((templateState) => {
      console.log(templateState, "模板信息==");
      const hasTree = !templateState.hasOwnProperty(
        "vaildFailureTemplateInnerSearchPath"
      );
      const appendReqParams = {};
      if (hasTree) {
        //////////////////////
        setterCrudServiceVmTemplateConfig("tree", templateState);
        //////////////////////

        filter_setterRemoteTableConfig(templateState);

        filter_setterAllTableBtnsConfig(templateState);
        //////////////////////
        filter_getFirstItemAppendReqParamsIntoSearchForm(appendReqParams);
        treeLoading.value = false;
        hasLeftTree.value = hasTree;
      }
      /* 传递后面一个Promise链需要的参数 */
      return Promise.resolve({
        store: templateState.store,
        appendReqParams,
      });
    })
    .then(async (res) => {
      const templateState = await useGetCurUiTemplateInfo({
        templateName: templateName,
        templateIdx: props.templateIdx,
        store: res.store,
        isUseStaticResource: isUseStaticResource.value,
        staticResource: props.staticResource,
        appendReqParams: res.appendReqParams,
      });
      console.log(templateState, "当前模板状态===========");
      ////////////////////////
      setterCrudServiceVmTemplateConfig("table", templateState);
      ///////////////////////
      //console.log("请求的页面模板数据====", templateState);
      /////////设置模板容器尺寸：设计时、运行时
      setterTemplateContainerAttr(templateState);
      /////////////////////////
      setterRemoteTableConfig(templateState);
      ////////////////
      setterRemoteSearchFormConfig(templateState);
      setterAllTableBtnsConfig(templateState);

      tableLoading.value = false;
      _emits("biz-pagegen-data-ok", {
        staticResource: props.staticResource,
        staticAllBtnsEmitFormItemMetaConfig:
          allBtnsEmitFormItemMetaConfig.value,
        staticFilterAllBtnsEmitFormItemMetaConfig:
          filter_allBtnsEmitFormItemMetaConfig.value,
        //operationBtnsConfig: operationBtnsConfig.value,
        //toolBarConfig: toolBarConfig.value,
        //filter_toolBarConfig: filter_toolBarConfig.value,
        //filter_operationBtnsConfig: filter_operationBtnsConfig.value,
        //filter_tableCommonAttr: filter_tableCommonAttr.value,
        ////filter_tableBodyData,
        staticFilterDialogFormItemDynmicConfigList:
        filter_dialogFormItemDynmicConfigList.value,
        //////
        //tableCommonAttr: tableCommonAttr.value,
        staticTableColMetaList: tableColMetaList.value,
        staticTableColumnDynmicConfigList: tableColumnDynmicConfigList.value,
        //tableBodyData,
        staticDialogFormItemDynmicConfigList:
          dialogFormItemDynmicConfigList.value,
        //
        staticSearchFormItemMetaList: searchFormItemMetaList.value,
        staticSearchFormItemDynmicConfigList:
          searchFormItemDynmicConfigList.value,
        //searchFormCommonAttr: searchFormCommonAttr.value,
        //searchFormData,
      });
    })
    .catch((err) => {
      console.log(err);
    });
};

initMetaAndData({
  allOverrideParams: [{ templateInnerSearchPath: "", appendReqParams: {} }],
});

/////////
provide("crudServiceVmTemplateConfig", crudServiceVmTemplateConfig);
/** 以下两个是左树点击后传给右表的参数,需要在左树点击时间内赋值 */
provide("fillFieldsIntoAddForm", fillFieldsIntoAddForm);
provide("appendFieldsIntoSearchForm", appendFieldsIntoSearchForm);
provide("tablePageReq", tablePageReq);
const sceneTreeRef = ref(null);
const tableRef = ref(null);

// scene-container-gen:end

const refreshCompMetaDataProxy = computed(() => {
  return tableRef.value.tableFormBoxRef.tableOperationMethods
    .refreshTableMetaData;
});

/* const table_bizVariantConfig = useSkeletonDynmicTableSize({
  toolBarConfig: toolBarConfig,
  searchFormItemMetaList: searchFormItemMetaList.value,
  tableCommonAttr: tableCommonAttr.value,
}); */

defineExpose({
  // scene-container-expose:start
  //···
  //以下为优速搭系统暴露的变量
  filter_tableBodyData,
  refreshCompMetaDataProxy,
  initMetaAndData,
  // scene-container-expose:end
});
</script>
